<template>
  <div class="my_div">
    <img :src="url" alt="">
    <p :style="{backgroundColor:str}" @click="btnFn">{{uname}}</p>
  </div>
</template>

<script>
export default {
  data(){
    return{
      str:''
    }
  },
props:["url","uname"],
methods:{
  btnFn(uname){
    // 随机颜色
      this.str = `rgb(${Math.floor(Math.random() * 256)}, ${Math.floor(
        Math.random() * 256
      )}, ${Math.floor(Math.random() * 256)})`;
      // 触发父组件的函数 LiveDog 事件
    this.$emit("LiveDog",this.uname)
  }
}
}
</script>

<style>
.my_div{
  width: 200px;
  border:1px solid black;
  text-align: center;
  float: left;
}
.my_div img{
  width: 100%;
  height: 200px;
}
</style>
